package com.itasura.ehcache.repository;

import com.itasura.ehcache.entity.Product;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
 * @author sailor wang
 * @date 2018/11/12 6:19 PM
 * @description
 */
public interface ProductRepository extends JpaRepository<Product, Long> {

    //这里的单引号不能少，否则会报错，被识别是一个对象;
    @Cacheable(cacheNames = "product", value = "product", key = "'product_'+#code")
    List<Product> findByCode(String code);


    @CacheEvict(cacheNames = "product", value = "product", key = "'product_'+#code")
    void deleteByCode(String code);
}